/**
 *HideBorderAction.java
 *@anthor Daniel Liu
 *2006-4-26 7:27:30
 **/
package org.lex.utils.logging.handler.action;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;

import javax.swing.AbstractAction;
import javax.swing.AbstractButton;
import javax.swing.Action;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JRootPane;

public class HideBorderAction extends AbstractAction {
	private JFrame main = null;
	private JMenuBar mainMenuBar = null;
	private int windowDecorationStyle = JRootPane.FRAME;

	public HideBorderAction(JFrame parent) {
		super();
		this.main = parent;
		this.mainMenuBar = parent.getJMenuBar();
		this.putValue(Action.NAME, "Hide Border");
		this.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_I);
		this.putValue(Action.SELECTED_KEY, false);
	}

	public void actionPerformed(ActionEvent e) {
		boolean hide = ((AbstractButton) e.getSource()).isSelected();
		if (true == hide) {
			if (null == this.mainMenuBar)
				this.mainMenuBar = main.getJMenuBar();
			main.setJMenuBar(null);
			this.windowDecorationStyle = main.getRootPane().getWindowDecorationStyle();
			main.getRootPane().setWindowDecorationStyle(JRootPane.NONE);
		} else {
			main.setJMenuBar(this.mainMenuBar);
			main.getRootPane().setWindowDecorationStyle(windowDecorationStyle);
		}
	}
}
